package org.colafries.common.utils.excel;

import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import org.apache.poi.ss.usermodel.Cell;

/**
 * @author Ann
 * @version v1.0
 * @ClassName ExcelHandler
 * @Description
 * @date Created in 2025/3/27
 **/
public class SerialNumberHandler implements CellWriteHandler {

    @Override
    public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
        if (!isHead) {
            // 处理数据行：在第一列插入序号
            if (cell.getColumnIndex() == 0) {
                cell.setCellValue(relativeRowIndex + 1);  // 序号从 1 开始
            }
        }
    }
}
